/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GE_RUNTIME_CONTEXT_H
#define GE_RUNTIME_CONTEXT_H

#include "graph/tensor.h"
#include "register/runtime_attrs.h"

namespace ge {

class Node;

class GRAPH_API_EXPORT RuntimeContext {
public:
    RuntimeContext(ge::Node& node);
    virtual ~RuntimeContext() = default;
    /**
     * 根据输入index，获取输出tensor指针
     *
     * **注意：只有在`IMPL_OP`实现算子时，
     * 将对应输入设置为数据依赖后，才可以调用此接口获取tensor，否则行为是未定义的。**
     * @param index 输入index
     * @return 输入tensor指针，index非法时，返回空指针
     */
    const Tensor* GetInputTensor(const size_t index) const;

    /**
     * 基于算子IR原型定义，获取`OPTIONAL_INPUT`类型的输入tensor指针
     * @param ir_index IR原型定义中的index
     * @return tensor指针，index非法，或该INPUT没有实例化时，返回空指针
     */
    const Tensor* GetOptionalInputTensor(const size_t ir_index) const;

    virtual RuntimeAttrs* GetAttrs();

protected:
    virtual size_t GetRealIndex(const size_t ir_index, const size_t relative_index) const;
    const Shape* GetInputShapeByIndex(const size_t index) const;
    std::unique_ptr<RuntimeAttrs> runtimeAttrs_{nullptr};
    ge::Node& node_;
};

} // namespace ge


#endif

